package com.xd.core.system.controller;


import com.xd.common.exception.Assert;
import com.xd.common.exception.XkdException;
import com.xd.core.system.entity.SysPermission;
import com.xd.core.system.service.ISysPermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.security.Permissions;
import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author SJ
 * @since 2023-03-15
 */
@Api(tags = "权限信息")
@RestController
@RequestMapping("/core/sys-permission")
public class SysPermissionController {


    @Autowired
    private ISysPermissionService sysPermissionService;

    @ApiOperation("新增权限")
    @PostMapping("/addPer")
    public void addPer(@RequestBody SysPermission entity) {
        sysPermissionService.addPer(entity);
    }

    @ApiOperation("修改权限")
    @PutMapping("updatePer")
    public void updatePer(@RequestBody SysPermission entity) {
        sysPermissionService.updatePer(entity);
    }

    @ApiOperation("删除权限")
    @DeleteMapping("deletePer")
    public void deletePer(Integer id) {
        sysPermissionService.deletePer(id);
    }


    @PreAuthorize("hasAnyAuthority('sys:Permissions')")
    @ApiOperation("权限列表")
    @GetMapping("/getOpenPerList")
    public List<SysPermission> getOpenList() {
        return sysPermissionService.getOpenList();
    }
    /**
     * 新增角色权限列表
     */
    @ApiOperation("权限树(角色新增)")
    @GetMapping("/getAddList")
    public List<SysPermission> getAddList() {
        return sysPermissionService.getAddList();
    }

    /**
     * 修改角色权限列表
     */
    @ApiOperation("权限树(角色修改)")
    @GetMapping("/getUpdateList")
    public List<SysPermission> getUpdateList(Integer roleId) {
        return sysPermissionService.getUpdateList(roleId);
    }

    /**
     * 角色权限返显
     */
    @ApiOperation("员工角色权限返显")
    @GetMapping("/userPers")
    public List<SysPermission> userPers(Integer roleId) {
        return sysPermissionService.userPers(roleId);
    }
}
